package com.zj.system.controller;

import com.seventh.common.pojo.R;
import com.zj.system.aop.LogAnnotation;
import com.zj.system.pojo.entity.User;
import com.zj.system.pojo.vo.ChangePWSVo;
import com.zj.system.pojo.vo.PassWordVo;
import com.zj.system.pojo.vo.UserVo;
import com.zj.system.service.UserService;

import com.zj.system.utils.OSSUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @program: clms-seventh
 * @description: 用户控制层
 * @author: 张静
 * @create: 2021-07-19 16:20
 **/
@RestController

@RequestMapping("system/user")
@ApiModel(value = "用户控制层",description = "用户控制层")
public class UserController {
    @Autowired
    UserService userService;
    @PostMapping("sel/{currentPage}/{pageSize}")
    @ApiModelProperty("搜索分页查询用户")
    @LogAnnotation(title ="用户接口", action ="搜索分页查询用户",businessType = "0")
    public R selR(@ApiParam("当前显示的页码")@PathVariable("currentPage") Integer currentPage,
                  @ApiParam("每页显示的条数")@PathVariable("pageSize") Integer pageSize,
                  @ApiParam("前端传入的搜索数据")@RequestBody UserVo userVo){
        return userService.sel(pageSize,currentPage,userVo);
    }

    @PutMapping("up/{userId}/{status}")
    @ApiModelProperty("更新用户状态")
    @LogAnnotation(title ="用户接口", action ="更新用户状态",businessType = "2")
    public R upStatus(@ApiParam("用户ID")@PathVariable("userId") Integer userId,
                      @ApiParam("用户状态值")@PathVariable("status") Integer status){
        return userService.upStatus(userId,status);
    }
    @PutMapping("updateUserById")
    @ApiModelProperty("更新用户信息")
    @LogAnnotation(title ="用户接口", action ="更新用户信息",businessType = "2")
    public R update(@ApiParam("用户信息")@RequestBody User user){
        return userService.up(user);
    }
    @PostMapping("insertUser")
    @ApiModelProperty("新增用户信息")
    @LogAnnotation(title ="用户接口", action ="新增用户信息",businessType = "1")
    public R insertUser(@ApiParam("用户信息")@RequestBody User user){
        return userService.ins(user);
    }
    @GetMapping("selById/{userId}")
    @ApiModelProperty("根据用户ID查询用户信息")
    @LogAnnotation(title ="用户接口", action ="根据用户ID查询用户信息",businessType = "0")
    public R selById(@ApiParam("用户ID")@PathVariable("userId") Integer userId){
        return userService.selById(userId);
    }
    @DeleteMapping("del/{userId}")
    @ApiModelProperty("根据用户ID删除用户信息")
    @LogAnnotation(title ="用户接口", action ="根据用户ID删除用户信息",businessType = "3")
    public R del(@ApiParam("用户ID")@PathVariable("userId") Integer userId){
        return userService.del(userId);
    }

    @PostMapping("selUserName")
    @ApiModelProperty("查询用户账号是否唯一")
    @LogAnnotation(title ="用户接口", action ="查询用户账号是否唯一",businessType = "0")
    public R selUserName(@ApiParam("用户信息")@RequestBody User user){
        return userService.selUserName(user);
    }
    @PostMapping("selPhone")
    @ApiModelProperty("查询手机号是否唯一")
    @LogAnnotation(title ="用户接口", action ="查询手机号是否唯一",businessType = "0")
    public R selPhone(@ApiParam("用户信息")@RequestBody User user){
        return userService.selPhone(user);
    }
    @PostMapping("selEmail")
    @ApiModelProperty("查询邮箱是否唯一")
    @LogAnnotation(title ="用户接口", action ="查询邮箱是否唯一",businessType = "0")
    public R selEmail(@ApiParam("用户信息")@RequestBody User user){
        return userService.selEmail(user);
    }
    @PostMapping("upPicture")
    @ApiModelProperty("头像上传")
    @LogAnnotation(title ="用户接口", action ="头像上传",businessType = "2")
    public String upPicture(@ApiParam("头像文件")MultipartFile file){
        return OSSUtil.upload2(file);
    }
    @ApiModelProperty("修改密码")
    @PostMapping("upPassword")
    @LogAnnotation(title ="用户接口", action ="修改密码",businessType = "2")
    public R upPassword(@ApiParam("前端传入的修改密码数据")@RequestBody PassWordVo vo){
        return userService.upPassword(vo);
    }
    @GetMapping({"selByUserName/{userName}"})
    @LogAnnotation(
            title = "用户接口",
            action = "查询账号",
            businessType = "0"
    )
    public R selByUserName(@ApiParam("前端传入的账号数据") @PathVariable("userName") String userName) {
        return this.userService.selByUserName(userName);
    }

    @PostMapping({"changeforgetpsw"})
    @ApiModelProperty("新增用户信息")
    @LogAnnotation(
            title = "用户接口",
            action = "修改密码",
            businessType = "2"
    )
    public R changeforgetpsw(@ApiParam("用户信息") @RequestBody ChangePWSVo vo) {
        return this.userService.changeForgetPsw(vo);
    }
}
